package cn.zzuli.myfirstapp;

import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;

public class MainActivity2 extends AppCompatActivity {

    private EditText et_username;
    private EditText et_password1;
    private EditText et_password2;
    private String name,pwd1,pwd2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initEvent();
    }
    private void initEvent() {
//        findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                showDialog1();
//            }
//        });
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog2();
            }
        });
    }
    private void showDialog2() {
        et_username =(EditText) findViewById(R.id.textView);
        et_password1 =(EditText) findViewById(R.id.textView2);
        et_password2 =(EditText) findViewById(R.id.textView3);
        name = et_username.getText().toString().trim();
        pwd1 = et_password1.getText().toString().trim();
        pwd2 = et_password2.getText() .toString().trim();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if ( (name == "") || (name.length() == 0)
                && (pwd1 == "") || (pwd2.length() == 0)) {
            builder.setMessage("注册失败");
        }
        else{
            builder.setMessage("注册成功");
        }
        builder.setPositiveButton("我知道了",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();

    }
}
